package com.shoppingwebsite.service.impl;

import com.shoppingwebsite.dao.GoodsDao;
import com.shoppingwebsite.domain.YtGoods;
import com.shoppingwebsite.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class GoodsServiceImpl implements GoodsService {
    @Autowired
    private GoodsDao goodsDao;


    @Override
    public List<YtGoods> selectAll() {
        List<YtGoods> goods = goodsDao.selectAll();
        return goods;
    }

    @Override
    public List<YtGoods> selectByName(String name) {
        List<YtGoods> goods = goodsDao.selectByName(name);
        return goods;
    }

    @Override
    public void buyGoods(String names) {
        //获得所有需购买的商品
        String name[]=names.split(",");
        for(int i=0;i<name.length;i++){
            goodsDao.buyGoods(name[i]);
        }
    }

    @Override
    public List<YtGoods> search(String sort) {
        return goodsDao.search(sort);
    }
}
